function uh = assemble_solution_1d(node, elem, dN, U)

piecewise_function = cell(size(elem,1), 1);
local_domain = zeros(size(elem,1), 2);

for n = 1:size(elem,1)
    E = node(elem(n,:));
    a = E(1);
    b = E(2);
    local_domain(n,:) = [a, b];
    phi = function_transform_1d(-1, 1, dN, a, b);
    sum = @(x) 0;
    for beta = 1:size(elem,2)
        i = elem(n,beta);
        sum = @(x) sum(x) + U(i).*phi{beta}(x);
    end
    piecewise_function{n} = @(x) sum(x);
end

uh = @(x) arrayfun(@(xi) piecewise_function{find(local_domain(:,1) <= xi & xi <= local_domain(:,2), 1)}(xi), x);

end